import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_category.dart';

import 'mine_my_rank_item_level_page.dart';
import 'mine_my_score_page.dart';
import 'mine_my_scroe_item_level_page.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/1/13.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class MineMyScoreItemPage extends StatefulWidget {
  final CategoryBean categoryBean;
  final StreamController<String> dateSelectStream;
  final ScoreRankType scoreRankType;

  MineMyScoreItemPage(
      {this.categoryBean,
      this.dateSelectStream,
      this.scoreRankType = ScoreRankType.score,
      Key key})
      : super(key: key);

  @override
  _MineMyScoreItemPageState createState() => _MineMyScoreItemPageState();
}

class _MineMyScoreItemPageState extends State<MineMyScoreItemPage>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
    initTabFunction();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        TabBar(
          isScrollable: true,
          controller: _tabController,
          tabs: _tabList,
        ),
        Expanded(
          child: TabBarView(
            controller: _tabController,
            children: _tabBarViewList,
          ),
        ),
      ],
    );
  }

  List<CategoryItemBean> _list = [];
  TabController _tabController;
  List<Tab> _tabList = [];
  List<Widget> _tabBarViewList = [];

  void initTabFunction() {
    if (widget.scoreRankType == ScoreRankType.integralStatistics) {
    } else {
      _list = widget.categoryBean.children;
      _tabController = new TabController(vsync: this, length: _list.length);
      if (widget.scoreRankType == ScoreRankType.score) {
        _list.forEach((element) {
          _tabList.add(Tab(
            text: "${element.categoryName}",
          ));
          _tabBarViewList.add(
            MineMyScoreItemLevelPage(
              categoryOne: widget.categoryBean.categoryCode,
              categoryItemBean: element,
              dateSelectStream: widget.dateSelectStream,
            ),
          );
        });
      } else {
        _list.forEach((element) {
          _tabList.add(Tab(
            text: "${element.categoryName}",
          ));
          _tabBarViewList.add(
            MineMyRahkItemLevelPage(
              categoryOne: widget.categoryBean.categoryCode,
              categoryItemBean: element,
              dateSelectStream: widget.dateSelectStream,
            ),
          );
        });
      }
    }

    Future.delayed(Duration.zero, () {
      setState(() {});
    });
  }
}
